package com.cmse.web.action.admin;

import java.util.Date;

import org.apache.struts2.ServletActionContext;

import com.cmse.constant.GlobalConstants;
import com.cmse.persistence.domain.SiteInfo;
import com.cmse.service.ISiteInfoService;
import com.cmse.web.action.BaseAction;

/**
 * @author wulibin, exceptsky@gmail.com, 2012-3-15 下午5:36:56
 * 
 */
public class SiteInfoAction extends BaseAction {
	private static final long serialVersionUID = -4954077033863374527L;
	private ISiteInfoService siteInfoService;
	private SiteInfo siteinfo;
	
	public String siteOption()throws Exception{
		SiteInfo oldSiteInfo = siteInfoService.get();
		oldSiteInfo.setTitle(siteinfo.getTitle());
		oldSiteInfo.setDomain(siteinfo.getDomain());
		oldSiteInfo.setDescription(siteinfo.getDescription());
		oldSiteInfo.setSubTitle(siteinfo.getSubTitle());
		oldSiteInfo.setBeian(siteinfo.getBeian());
		oldSiteInfo.setKeyWords(siteinfo.getKeyWords());
		oldSiteInfo.setCustomCode(siteinfo.getCustomCode());
		siteinfo.setModifiedAt(new Date());
		siteInfoService.update(oldSiteInfo);
		ServletActionContext.getServletContext().setAttribute(GlobalConstants.ATTRIBUTE_SITEINFO, oldSiteInfo);
		return SUCCESS;
	}
	
	public String readOption()throws Exception{
		SiteInfo oldSiteInfo = siteInfoService.get();
		oldSiteInfo.setModifiedAt(new Date());
		siteInfoService.update(oldSiteInfo);
		ServletActionContext.getServletContext().setAttribute(GlobalConstants.ATTRIBUTE_SITEINFO, oldSiteInfo);
		return SUCCESS;
	}
	
	public String commentOption()throws Exception{
		SiteInfo oldSiteInfo = siteInfoService.get();
		oldSiteInfo.setArticalCommentOn(siteinfo.getArticalCommentOn());
		oldSiteInfo.setArticalAnonymousCommentOn(siteinfo.getArticalAnonymousCommentOn());
		oldSiteInfo.setCommentVerify(siteinfo.getCommentVerify());
		oldSiteInfo.setModifiedAt(new Date());
		siteInfoService.update(siteinfo);
		ServletActionContext.getServletContext().setAttribute(GlobalConstants.ATTRIBUTE_SITEINFO, oldSiteInfo);
		return SUCCESS;
	}

	public ISiteInfoService getSiteInfoService() {
		return siteInfoService;
	}

	public void setSiteInfoService(ISiteInfoService siteInfoService) {
		this.siteInfoService = siteInfoService;
	}

	public void setSiteinfo(SiteInfo siteinfo) {
		this.siteinfo = siteinfo;
	}

	public SiteInfo getSiteinfo() {
		return siteinfo;
	}
	
}